#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
 struct TreeNode {
         int val;
         TreeNode *left;
         TreeNode *right;
         TreeNode(int x) : val(x), left(NULL), right(NULL) {}
     };

 bool helper(TreeNode*root,int lower,int upper){
     if(root== nullptr)return true;

     int val=root->val;
     cout<<val<<","<<lower<<","<<upper<<endl;
     if((lower!=NULL||lower==0)&&val<=lower){cout<<"here"<<endl;return false;}
     if((upper!=NULL||lower==0)&&val>=upper){cout<<"here1"<<endl;return false;}

     if(!helper(root->right,val,upper))return false;
     if(!helper(root->left,lower,val))return false;
     return true;
 }

 bool isValidBST(TreeNode* root) {
    return helper(root,NULL, NULL);
}

int main(){
//    TreeNode*root=new TreeNode(2);
//    root->left=new TreeNode(1);
//    root->right=new TreeNode(3);
//    TreeNode*root=new TreeNode(5);
//    root->left=new TreeNode(1);
//    root->right=new TreeNode(4);
//    root->right->left=new TreeNode(3);
//    root->right->right= new TreeNode(6);
    TreeNode*root=new TreeNode(1);
    root->right=new TreeNode(-1);
    cout<<isValidBST(root);
    return 0;
}